<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // function Mon(name, age){
        //     this.name = name
        //     this.age = age
        // }
        // Mon.prototype = {
            
        // }

        // es6引入了类的概念，创建每一个class类，里面都会有一个构造函数方法
        class Monkey{
            constructor(name, age) {
                this.name = name
                this.age = age
                this.like = function() {
                    console.log("大闸蟹")
                }
            }

            showName(eat) {
                console.log(this.name + "喜欢吃" + eat)
            }
            // 相当于
            // Monkey.prototype.showName = function() {}

        }

        let sun = new Monkey("孙悟空", 200)
        sun.like()
        console.log(sun.name);
        sun.showName("桃子")

        // 继承 Extends
        class Sunwukong extends Monkey {
            constructor(name, age, color) {
                // super() 使用extands 必须使用 super来调用父类的构造方法
                super(name,age)
                this.color = color
            }
            showName(eat) {
                super.showName(eat)
            }
            showColor() {
                console.log("颜色是" + this.color)
            }
        }

        let wuk = new Sunwukong("美猴王", 500, "黄色")

        wuk.like()
        wuk.showName("香蕉")
        wuk.showColor()

    </script>
</body>
</html>